package org.microservice.service.feign;

import feign.hystrix.FallbackFactory;
import org.microservice.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignClientFallbackFactory.class);


    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User findById(Long id) {
                LOGGER.info("fallback reason was:", throwable);
                User user = new User();
                user.setId(-1L);
                user.setName("[feign back factory] 默认用户");
                return user;
            }
        };
    }
}
